﻿/*
{
"状态":1,
"名称":"获取-店铺属性值",
"作者":"马学兵",
"创建时间":"2018-12-30",
"功能":"获取-店铺属性值",
"log": [
	{"date":"06-01" , "dev" :"hzhh" , "content" : ""}
]
}
*/
--前端调用
DECLARE @users VARCHAR(4000) 
DECLARE @dict_id VARCHAR(10) 
DECLARE @val NVARCHAR(1000)

--定义变量
DECLARE @field NVARCHAR(100)

set @users='{users}'
set @dict_id='{dict_id}'
set @val='{val}'


SET @field=CASE  @dict_id 
WHEN '10801' THEN 'all'
WHEN '10802' THEN 'entity_code '
WHEN '10803' THEN 'entityName'
WHEN '10804' THEN 'short_name'
WHEN '10805' THEN 'entity_type'
WHEN '10806' THEN 'company'
WHEN '10807' THEN 'area' 
WHEN '10808' THEN 'group'
WHEN '10809' THEN 'province'
WHEN '10810' THEN 'city'
WHEN '10811' THEN 'county'
WHEN '10812' THEN 'supervisor' else '' END 
 
if @field=''
begin 
	RAISERROR ('店铺不存在该属性', 16 ,1 ) ; 
	return
end 

if @field<>'all' and @val=''
begin
	RAISERROR ('该属性值不允许为空', 16 ,1 ) ; 
	return
end 

INSERT INTO b_entity_right(user_key,attribute,val)
SELECT A.value,@field,@val FROM  dbo.Ft_Split(@users,',') A LEFT join b_entity_right   B ON A.value=B.user_key AND attribute=@field
WHERE B.user_key IS NULL 